﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Akiha.Core
{
    public class DataTableWrapper
    {
        public static int GetValueCount(DataTable DT, string columnName, string value)
        {
            int count = 0;
            for (int i = 0; i < DT.Rows.Count; i++)
            {
                DataRow dtrow = DT.Rows[i];
                if (dtrow.RowState == DataRowState.Deleted)
                {
                    continue;
                }

                if (DT.Rows[i][columnName].ToString().ToUpper() == value.ToUpper())
                {
                    count += 1;
                }
            }

            return count;
        }

        public static List<string> GetValues(DataTable DT, string compareName, string compareValue, string queryName)
        {
            List<string> values = new List<string>();
            for (int i = 0; i < DT.Rows.Count; i++)
            {
                if (DT.Rows[i][compareName].ToString().ToUpper() == compareValue.ToUpper())
                {
                    string queryValue = DT.Rows[i][queryName].ToString();
                    if (!values.Contains(queryValue))
                    {
                        values.Add(DT.Rows[i][queryName].ToString());
                    }
                }
            }

            return values;
        }
    }
}
